void DirectionalLight(in int i, in vec3 normal,
		inout vec4 ambient, inout vec4 diffuse, inout vec4 specular);
void PointLight(in int i, in vec3 eye, in vec3 ecPosition3, in vec3 normal,
		inout vec4 ambient, inout vec4 diffuse, inout vec4 specular);
void main()
{
	vec4 ambient = vec4(0.0,0.0,0.0,0.0);
	vec4 diffuse = vec4(0.0,0.0,0.0,0.0);
	vec4 specular = vec4(0.0,0.0,0.0,0.0);
	
	// Calculate the eye position
	vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;
	vec3 ecPosition3 = (vec3(ecPosition)) / ecPosition.w;
	vec3 eye = vec3(0,0,1);
    // transform vertex to clip space coordinates
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    // Calculate the lighting
    vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
    for(int i=0; i <4; i++)
    {
    	if( gl_LightSource[i].position.w == 0.0)
    		DirectionalLight(i, normal, ambient, diffuse, specular);
    	else
    		PointLight(i, eye, ecPosition3, normal, ambient, diffuse, specular);
    }
    // Set the color
    specular = specular * gl_FrontMaterial.specular;
    vec4 color = gl_FrontLightModelProduct.sceneColor + ambient * gl_FrontMaterial.ambient
    			+ diffuse * gl_FrontMaterial.diffuse
    			+ specular;
    gl_FrontColor = color;
}



